package com.qqt.csr.im.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.qqt.csr.common.enums.YesOrNotEnum;
import com.qqt.csr.common.utils.SnowflakeUtil;
import lombok.*;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.Date;

/**
 * 敏感词
 */
@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ToString
@Accessors(chain = true)
@JsonIgnoreProperties(ignoreUnknown = true)
@TableName(value = "csr_sensitive_word")
public class SensitiveWord implements Serializable {
    /**
     * 主键
     */
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    private Long id;

    /**
     * 创建时间
     */
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private Date createTime;

    /**
     * 创建人id
     */
    @TableField(value = "creator_id")
    private Long creatorId;

    /**
     * 是否移除：0 否；1 是
     */
    @TableLogic(value = "0", delval = "1")
    @TableField(value = "delete_flag")
    private Integer deleteFlag;

    /**
     * 是否启用：0 否；1 是
     */
    @TableField(value = "`enable`")
    private Integer enable;

    /**
     * 词库名称
     */
    @TableField(value = "`name`")
    private String name;

    /**
     * 词库id
     */
    @TableField(value = "repo_id")
    private Long repoId;

    /**
     * 租户编号
     */
    @TableField(value = "tenant_id")
    private String tenantId;

    /**
     * 更新时间
     */
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    private Date updateTime;

    private static final long serialVersionUID = 1L;

    @JsonIgnore
    public static SensitiveWord of(String tenantId, Long creatorId, Long repoId, String name) {
        return SensitiveWord.builder()
                .id(SnowflakeUtil.nextId())
                .creatorId(creatorId)
                .repoId(repoId)
                .tenantId(tenantId)
                .enable(YesOrNotEnum.NOT.getValue())
                .deleteFlag(YesOrNotEnum.NOT.getValue())
                .createTime(new Date())
                .updateTime(new Date())
                .name(name.length() > 30 ? name.substring(0, 30) : name)
                .build();
    }
}